﻿function Get-ServiceAttributes
{
	<#
	.Synopsis
        Gets the current state of all services under the specified account
	.Description
        Gets the servicename, startmode, and state of each service running under a service account
	.Parameter Server
	    Server name
	.Parameter ServiceAccount
	    Name of "Run As" Service Account 
    #>

    [cmdletbinding()]
	Param(
	[Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()]
	[string] $Server,
	[Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()]
	[string] $ServiceAccount
    )

    try
    {        
        $services = Get-WmiObject win32_service  -ComputerName $server -ErrorAction Stop | Where-Object {$_.StartName -Like $serviceAccount} -ErrorAction Stop | Select-Object Name, StartMode, State
    }
    catch [exception]
    {
        $failMessage = "$($_.Exception.ToString()). $($_.InvocationInfo.PositionMessage)" + "Failed to get service attributes"
        return $failMessage
    }
    return $services
}